package com.hzb.LNReader.view;

import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.View.OnTouchListener;

public class ReaderTouchListener implements OnTouchListener {
	private GestureDetector detector;
	
	public ReaderTouchListener(ReaderView view) {
		detector = new GestureDetector(new ReaderGestureListener(view));
	}
	
	@Override
	public boolean onTouch(View v, MotionEvent event) {
		return detector.onTouchEvent(event);
	}
}

class ReaderGestureListener extends SimpleOnGestureListener {
	private ReaderView view;
	
	public ReaderGestureListener(ReaderView view) {
		this.view = view;
	}

//	@Override
//	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
//			float velocityY) {
//		// TODO Auto-generated method stub
//		return super.onFling(e1, e2, velocityX, velocityY);
//	}

//	@Override
//	public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
//			float distanceY) {
//		// TODO Auto-generated method stub
//		return super.onScroll(e1, e2, distanceX, distanceY);
//	}


	@Override
	public boolean onSingleTapConfirmed(MotionEvent e) {
		int h = view.getHeight();
		if (e.getY() > (h >> 1)) {
			view.scrollNextPage();
		} else {
			view.scrollPrevPage();
		}
		return true;
	}

}
